package com.smm.controller;

import com.jn.sqlhelper.dialect.pagination.PagingResult;
import com.smm.common.Result;
import com.smm.entity.Comment;
import com.smm.service.CommentService;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("comment")
@Api(value = "smm", tags = "Comment相关接口")
public class CommentController {
    private Logger log = LoggerFactory.getLogger(CommentController.class);
    @Resource
    private CommentService commentService;

    @PostMapping("/")
    public Result addComment(Comment comment) {
        return Result.SUCCESS(commentService.addComment(comment));
    }

    @DeleteMapping("/{id}")
    public Result deleteComment(@PathVariable("id") Integer id) {
        return Result.SUCCESS(commentService.deleteComment(id));
    }

    @GetMapping("/{id}")
    public Result findComment(@PathVariable("id") Integer id) {
        Comment comment = new Comment();
        comment.setId(id);
        return Result.SUCCESS(commentService.findComment(comment));
    }

    @GetMapping("/{pageSize}/{pageNumber}")
    public Result findCommentPage(@PathVariable("pageSize") Integer pageSize,
                                  @PathVariable("pageNumber") Integer pageNumber,
                                  Comment comment) {

        log.info(String.valueOf(comment));
        PagingResult comments = commentService.findCommentPage(comment, pageSize, pageNumber);
        return Result.SUCCESS(comments);
    }

    @PutMapping("/")
    public Result updateComment(@RequestBody Comment comment) {
        return Result.SUCCESS(commentService.updateComment(comment));
    }
}
